package com.yfl.tingyu.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yfl.tingyu.pojo.Role;
import com.yfl.tingyu.pojo.RoleMenu;
import com.yfl.tingyu.service.impl.RoleMenuServiceImpl;
import com.yfl.tingyu.service.impl.RoleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDateTime;
import java.util.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2020-05-26
 */
@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleServiceImpl roleService;

    @Autowired
    private RoleMenuServiceImpl roleMenuService;

    @RequestMapping("/roleManager")
    public String roleManager(){

        return "roleManager";
    }

    @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> list(Integer page, Integer rows){

        Map<String, Object> role = roleService.selectRole(page, rows);

        return  role;
    }

    //添加角色
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Boolean saveOrUpdate(Role role,Integer[] mids){

        boolean saveOrUpdate =roleService.insertOrUpdate(role,mids);

        return saveOrUpdate;
    }

    //删除角色
    @RequestMapping("/deleteCompnay")
    @ResponseBody
    public Boolean deleteCompnay(Integer[] rids){

        boolean remove = roleService.removeRoleMenu(rids);
        return remove;
    }

    @RequestMapping("/getRoleMenu")
    @ResponseBody
    public List<Integer> getRoleMenu(Integer rid){


        List<RoleMenu> integers = roleMenuService.seleteRoleMenu(rid);

        List<Integer> mids=new ArrayList<>();
        for (RoleMenu integer : integers) {
            mids.add(integer.getMid());
        }
        return mids;
    }


}

